package com.demo.strategy.st_02;

import java.math.BigDecimal;

/**
 * @Author: shubin_yao
 * @Date: 2022/05/15/22:58
 * @Description: 折扣
 */
public class ZKCouponDiscount implements ICouponDiscount<Double> {
    /**
     * 折扣计算
     * 1. 使⽤商品价格乘以折扣⽐例，为最后⽀付⾦额
     * 2. 保留两位⼩数
     * 3. 最低⽀付⾦额1元
     */
    public BigDecimal discountAmount(Double couponInfo, BigDecimal
            skuPrice) {
        BigDecimal discountAmount = skuPrice.multiply(new
                BigDecimal(couponInfo)).setScale(2, BigDecimal.ROUND_HALF_UP);
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) return
                BigDecimal.ONE;
        return discountAmount;
    }
}
